
// BBViewer.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include "afxwinappex.h"
#include "BBViewer.h"
#include "MainFrm.h"
#include "UIConst.h"
#include "../_inc_util/UtilLog.h"
#include "../_inc_util/UtilFormatDrive.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CBBViewerApp

BEGIN_MESSAGE_MAP(CBBViewerApp, CWinAppEx)
	// Standard file based document commands
	ON_COMMAND(ID_FILE_NEW, &CWinAppEx::OnFileNew)
	ON_COMMAND(ID_FILE_OPEN, &CWinAppEx::OnFileOpen)
END_MESSAGE_MAP()


// CBBViewerApp construction

CBBViewerApp::CBBViewerApp()
{
	m_bHiColorIcons = TRUE;
}

// The one and only CBBViewerApp object

CBBViewerApp theApp;


// CBBViewerApp initialization

BOOL CBBViewerApp::InitInstance()
{
	// InitCommonControlsEx() is required on Windows XP if an application
	// manifest specifies use of ComCtl32.dll version 6 or later to enable
	// visual styles.  Otherwise, any window creation will fail.
	INITCOMMONCONTROLSEX InitCtrls;
	InitCtrls.dwSize = sizeof(InitCtrls);
	// Set this to include all the common control classes you want to use
	// in your application.
	InitCtrls.dwICC = ICC_WIN95_CLASSES;
	InitCommonControlsEx(&InitCtrls);

	WSADATA wsd;
	InitW2Sock(&wsd);

	CWinAppEx::InitInstance();

	// Standard initialization
	// If you are not using these features and wish to reduce the size
	// of your final executable, you should remove from the following
	// the specific initialization routines you do not need
	// Change the registry key under which our settings are stored
	// TODO: You should modify this string to be something appropriate
	// such as the name of your company or organization
	SetRegistryKey(_T("BBViewer"));


	//////////////////////////////////////////////////////////////////////////
	//GetModulePath
 	TCHAR tzModulePath[MAX_PATH]={0};
 	GetModuleFileName(GetModuleHandle(NULL) , tzModulePath , MAX_PATH);

 	m_strModulePath.Format(_T("%s"), tzModulePath);
 	int nPos = m_strModulePath.ReverseFind('\\');
 	m_strModulePath.Delete(nPos, m_strModulePath.GetLength()-nPos);

	//////////////////////////////////////////////////////////////////////////
	GetLogoPath();

	//////////////////////////////////////////////////////////////////////////
	SystemParametersInfo(SPI_GETSCREENSAVETIMEOUT, 0, &m_nScreenSaveTimeout, SPIF_SENDCHANGE);
	SystemParametersInfo(SPI_SETSCREENSAVETIMEOUT, 0, NULL, SPIF_SENDCHANGE);

	CleanState();

	if (!InitGUI())
		return FALSE;

	InitDlgSize();

	CMainFrame* pFrame = new CMainFrame;
	m_pMainWnd = pFrame;


	// create and load the frame with its resources
	BOOL bOK = pFrame->LoadFrame(IDR_MAINFRAME, WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, NULL, NULL);

	// The one and only window has been initialized, so show and update it.
	if(!bOK) return FALSE;

	m_pMainWnd->ShowWindow(SW_SHOW);
	m_pMainWnd->UpdateWindow();

	return TRUE;
}

// CBBViewerApp customization load/save methods

void CBBViewerApp::PreLoadState()
{
}

void CBBViewerApp::LoadCustomState()
{
}

void CBBViewerApp::SaveCustomState()
{
}

// CBBViewerApp message handlers

BOOL CBBViewerApp::InitW2Sock(WSADATA * lpwsaData)
{
	WSADATA wsaData;

	if ( lpwsaData == NULL )
		lpwsaData = &wsaData;

	WORD wVersionRequested = MAKEWORD(2, 2) ;
	
	int nResult = WSAStartup( wVersionRequested, lpwsaData ) ;
	
	if (nResult != 0)
	{		
		return  FALSE;
	}

	if (LOBYTE(lpwsaData->wVersion) != 2 || HIBYTE(lpwsaData->wVersion) != 2)
	{
		WSACleanup();
		return FALSE;
	}

	return TRUE;
}

int CBBViewerApp::ExitInstance()
{
	WSACleanup();
	SystemParametersInfo(SPI_SETSCREENSAVETIMEOUT, m_nScreenSaveTimeout, NULL, SPIF_SENDCHANGE);
	UnloadImage();
	UnloadWinInfo();

	return CWinAppEx::ExitInstance();
}

void CBBViewerApp::InitDlgSize()
{
	dwScreenWidth = GetSystemMetrics(SM_CXSCREEN);
	dwScreenHeight = GetSystemMetrics(SM_CYSCREEN);

	ST_WND_POS stWndPos;
	if (m_SupportImage.GetWndInfo(WININFO_APP_MAINFRMAE, &stWndPos))
	{
		dwDefaultWidth = stWndPos.rtWndPos.Width();
		dwDefaultHeight = stWndPos.rtWndPos.Height();
	}
	else
	{
		dwDefaultWidth = CX_GAP*3+CX_MENU_RIGHT+CX_FRONT_VIEW;		//1091
		dwDefaultHeight = CY_GAP*3+CY_TITLE_BAR+CY_FRONT_VIEW+CY_REAR_VIEW+MAINFRAME_BAR_S;	//720
	}

	if ((dwDefaultWidth>dwScreenWidth)&&(dwDefaultHeight>dwScreenHeight))
	{
		dwWinWidth = dwScreenWidth;
		dwWinHeight = dwScreenHeight;
	}
	else if ((dwDefaultWidth<=dwScreenWidth)&&(dwDefaultHeight>dwScreenHeight))
	{
		dwWinWidth = dwDefaultWidth*dwScreenHeight/dwDefaultHeight;
		dwWinHeight = dwScreenHeight;
	}
	else if ((dwDefaultWidth>dwScreenWidth)&&(dwDefaultHeight<=dwScreenHeight))
	{
		dwWinWidth = dwScreenWidth;
		dwWinHeight = dwDefaultHeight*dwScreenWidth/dwDefaultWidth;
	}
	else	//if ((dwDefaultWidth<=dwScreenWidth)&&(dwDefaultHeight<=dwScreenHeight))
	{
		dwWinWidth = dwDefaultWidth;
		dwWinHeight = dwDefaultHeight;
	}
}

void CBBViewerApp::SetDlgSize()
{
	LPST_WND_POS lpWndPos = WndPos.GetAt(wpMainDisplay);
	LPST_WND_POS lpWndPosOption = WndPos.GetAt(wpOpt);

	dwDisplayWidth = dwWinWidth-(lpWndPos->rtStickTo.left+lpWndPosOption->rtStickTo.left+lpWndPosOption->rtStickTo.right+CX_MENU_RIGHT);
	dwDisplayHeight  = dwWinHeight-(dwDefaultHeight-CY_FRONT_VIEW);

}

void CBBViewerApp::InitDocPath()
{
	TCHAR tzDocPath[MAX_PATH];
	ZeroMemory(tzDocPath, sizeof(tzDocPath));
	if (SHGetSpecialFolderPath(NULL, tzDocPath, CSIDL_MYDOCUMENTS, TRUE))
	{
		m_strMyDocumentRoot.Format(_T("%s\\BBViewerDoc"), tzDocPath);

		int nRet = SHCreateDirectory(NULL, m_strMyDocumentRoot);
		if ((nRet != ERROR_SUCCESS)||(nRet != ERROR_ALREADY_EXISTS))
		{
			CreateDirectory(m_strMyDocumentRoot, NULL);
			TRACE(_T("GetLastError = %08X\n"), GetLastError());
		}
	}
}

BOOL CBBViewerApp::GetLangSupport(CString &strLang, LANGID &langID)
{
	UINT uRet = GetProfileInt(_T("Language"), _T("LangSupportAuto"), 1);
	strLang = GetProfileString(_T("Language"), _T("Manual Language"), _T("English"));
	langID = (LANGID)GetProfileInt(_T("Language"), _T("Manual Language ID"), 0x0C09);

	return (BOOL)uRet;
}

void CBBViewerApp::SetLangSupport(BOOL bAuto, CString strLang)
{
	int i;
	LANGID langID;
	CString strLangName;

	WriteProfileInt(_T("Language"), _T("LangSupportAuto"), (int)bAuto);

	if (!bAuto)
	{
		WriteProfileString(_T("Language"), _T("Manual Language"), strLang);
		for (i=0;i<m_sarrLangPath.GetSize();i++)
		{
			langID = m_SupportLang.GetLanguageID(strLangName, m_sarrLangPath.GetAt(i));
			if (strLang.Compare(strLangName) == 0)
			{
				WriteProfileInt(_T("Language"), _T("Manual Language ID"), langID);
			}
		}
	}
}

void CBBViewerApp::GetLanguageSupport()
{
	//parse language file
	CString strPath;
	CString strManualLang;
	int nPos;

	//step 1. Find language files
	m_sarrLangPath.RemoveAll();
	strPath.Format(_T("%s\\lang"), m_strModulePath);
	FindLanguagePath(strPath);

	TRACE(_T("Lang file = %d"), m_sarrLangPath.GetSize());

	if (m_sarrLangPath.GetSize() == 0)
	{
_NOT_MATCHED:
		m_sarrLangPath.RemoveAll();
		strPath.Format(_T("%s\\lang\\ENG\\lang_support.ini"), m_strModulePath);
		m_sarrLangPath.Add(strPath);
		m_SupportLang.LoadLangText(m_sarrLangPath.GetAt(0));

		m_strLangPath.Format(_T("%s\\lang\\ENG"), m_strModulePath);
		return;
	}

	LANGID langID = GetSystemDefaultLangID();
	LANGID langIDFromFile;
	CString strlangName;
	BOOL bAuto = GetLangSupport(strManualLang, langIDFromFile);
	int i;

	if (bAuto)
	{
	}
	else
	{
		langID = langIDFromFile;
	}

	for (i=0;i<m_sarrLangPath.GetSize();i++)
	{
		langIDFromFile = m_SupportLang.GetLanguageID(strlangName, m_sarrLangPath.GetAt(i));
		if (langID == langIDFromFile)
		{
			m_SupportLang.LoadLangText(m_sarrLangPath.GetAt(i));

			nPos = m_sarrLangPath.GetAt(i).ReverseFind('\\');
			m_strLangPath = m_sarrLangPath.GetAt(i).Left(nPos);
			break;
		}
	}

	if (i == m_sarrLangPath.GetSize())
	{
		for (i=0;i<m_sarrLangPath.GetSize();i++)
		{
			langIDFromFile = m_SupportLang.GetLanguageID(strlangName, m_sarrLangPath.GetAt(i));
			if ((langID&0x3FF) == (langIDFromFile&0x3FF))
			{
				m_SupportLang.LoadLangText(m_sarrLangPath.GetAt(i));
				nPos = m_sarrLangPath.GetAt(i).ReverseFind('\\');
				m_strLangPath = m_sarrLangPath.GetAt(i).Left(nPos);
				break;
			}
		}

		if (i == m_sarrLangPath.GetSize())
		{
			goto _NOT_MATCHED;
		}
	}
}

void CBBViewerApp::FindLanguagePath(CString strPath)
{
	CFileFind cFind;
	CString strFilePath;
	BOOL bWorking;
	strFilePath.Format(_T("%s\\lang*.ini"), strPath);

	bWorking = cFind.FindFile(strFilePath);
	while (bWorking)
	{
		bWorking = cFind.FindNextFile();

		CString strName;
		LANGID langID;
		langID = m_SupportLang.GetLanguageID(strName, cFind.GetFilePath());
		if (langID != 0x0000)
			m_sarrLangPath.Add(cFind.GetFilePath());
	}
	cFind.Close();

	strFilePath.Format(_T("%s\\*.*"), strPath);
	bWorking = cFind.FindFile(strFilePath);
	while (bWorking)
	{
		bWorking = cFind.FindNextFile();

		if (!cFind.IsDots() && cFind.IsDirectory())
		{
			FindLanguagePath(cFind.GetFilePath());	
		}
	}
	cFind.Close();
}

BOOL CBBViewerApp::GetLanguageList(int nIndex, CString &strLang)
{

	if (nIndex<m_sarrLangPath.GetSize())
	{
		m_SupportLang.GetLanguageID(strLang, m_sarrLangPath.GetAt(nIndex));
		return TRUE;
	}
	return FALSE;
}

BOOL CBBViewerApp::GetSkinList(int nIndex, CString &strSkin)
{
	CString strAppName;
	TCHAR tzName[MAX_PATH];
	TCHAR tzPath[MAX_PATH];
	DWORD dwRet;
	wsprintf(tzPath, _T("%s\\option\\ImagePath.ini"), m_strModulePath);
	strAppName.Format(_T("Image Path%d"), nIndex);
	dwRet = GetPrivateProfileString(strAppName, _T("Name"), NULL, tzName, MAX_PATH, tzPath);
	if (dwRet>0)
	{
		strSkin.Format(_T("%s"), tzName);
		return TRUE;
	}
	return FALSE;
}

int CBBViewerApp::GetSelectSkinList()
{
	TCHAR tzPath[MAX_PATH];
	wsprintf(tzPath, _T("%s\\option\\ImagePath.ini"), m_strModulePath);

	return GetPrivateProfileInt(_T("Setting"), _T("Select"), 0, tzPath);
}

void CBBViewerApp::SetSelectSkinList(int nIndex)
{
	TCHAR tzPath[MAX_PATH];
	wsprintf(tzPath, _T("%s\\option\\ImagePath.ini"), m_strModulePath);
	CString strValue;
	strValue.Format(_T("%d"), nIndex);

	WritePrivateProfileString(_T("Setting"), _T("Select"), strValue, tzPath);
}

CString CBBViewerApp::GetUIString(CString strAppName, CString strKeyName, CString strDefaultString)
{
	return m_SupportLang.GetString(strAppName, strKeyName, strDefaultString);
}

void CBBViewerApp::WriteRegString(CString strAppName, CString strKeyName, CString strValue)
{
	WriteProfileString(strAppName, strKeyName, strValue);
}

void CBBViewerApp::WriteRegInt(CString strAppName, CString strKeyName, int nValue)
{
	WriteProfileInt(strAppName, strKeyName, nValue);
}

//////////////////////////////////////////////////////////////////////////
void CBBViewerApp::InitLogPath()
{
	TCHAR tzPath[MAX_PATH];
	wsprintf(tzPath, _T("%s\\log"), m_strMyDocumentRoot);
	CreateDirectory(tzPath, NULL);

	_tcscpy_s(m_tzLogPath, tzPath);

	wsprintf(tzPath, _T("%s\\SystemProperty.log"), m_tzLogPath);

	CUtilLog ul;
	ul.WriteLogSystem(tzPath);
}

void CBBViewerApp::InitBackupPath()
{
	m_strBackupRoot.Format(_T("%s\\backup\\"), m_strMyDocumentRoot);
	CreateDirectory(m_strBackupRoot, NULL);
}

void CBBViewerApp::InitOptionPath()
{
	TCHAR tzPath[MAX_PATH];
	wsprintf(tzPath, _T("%s\\option"), m_strModulePath);
	CreateDirectory(tzPath, NULL);

	m_strOptionPath.Format(_T("%s\\%s"), tzPath, _T("Option.ini"));

	//////////////////////////////////////////////////////////////////////////
	//Get Option file path if no option file, create default

	CString strOptionPath;
	CFileFind cFind;
	BOOL bFind;

	strOptionPath.Format(_T("%s\\Option*.ini"), tzPath);

	bFind = cFind.FindFile(strOptionPath);

	while (bFind)
	{
		bFind = cFind.FindNextFile();

		m_sarrOptionPath.Add(cFind.GetFilePath());
	}
	cFind.Close();
}

CString CBBViewerApp::GetOptionPath(int nIndex)
{
	if (nIndex<m_sarrOptionPath.GetSize())
	{
		return m_sarrOptionPath.GetAt(nIndex);
	}
	return END_OF_OPTION_FILE;
}

void CBBViewerApp::InitOption()
{
	m_nDemo = GetPrivateProfileInt(_T("Option"), _T("Demo"), 0, m_strOptionPath);

	dwAudioFormat = GetPrivateProfileInt(_T("Audio"), _T("Format"), 1, m_strOptionPath);
	dwAudioFrequency = GetPrivateProfileInt(_T("Audio"), _T("Frequency"), 8081, m_strOptionPath);
	dwAudioBitPerSample = GetPrivateProfileInt(_T("Audio"), _T("BitPerSample"), 16, m_strOptionPath);
}

void CBBViewerApp::GetLatestPath(TCHAR *tzLatestPath, DWORD dwSize)
{
	GetPrivateProfileString(_T("Option"), _T("LatestPath"), _T(""), tzLatestPath, dwSize, m_strOptionPath);
}

void CBBViewerApp::WriteLatestPath(TCHAR *tzLatestPath, DWORD dwSize)
{
	WritePrivateProfileString(_T("Option"), _T("LatestPath"), tzLatestPath, m_strOptionPath);
}

int CBBViewerApp::GetDemoMode()
{
	return m_nDemo;
}


//////////////////////////////////////////////////////////////////////////
//GUI

BOOL CBBViewerApp::InitGUI()
{
	TCHAR tzPath[MAX_PATH];
	TCHAR tzValue[MAX_PATH];
	wsprintf(tzPath, _T("%s\\option"), m_strModulePath);
	CreateDirectory(tzPath, NULL);

	wsprintf(tzPath, _T("%s\\option\\ImagePath.ini"), m_strModulePath);

	int nSelect;
	CString strImagePath;
	nSelect = GetPrivateProfileInt(_T("Setting"), _T("Select"), 0, tzPath);

	strImagePath.Format(_T("Image Path%d"), nSelect);
	ZeroMemory(tzValue, sizeof(tzValue));
	GetPrivateProfileString(strImagePath, _T("Root Path"), NULL, tzValue, MAX_PATH, tzPath);
	m_strImageRoot.Format(_T("%s\\%s"), m_strModulePath, tzValue);
	ZeroMemory(tzValue, sizeof(tzValue));
	GetPrivateProfileString(strImagePath, _T("Info File Name"), NULL, tzValue, MAX_PATH, tzPath);
	m_strImageInfoFileName = tzValue;
	
	if (!m_SupportImage.SetImageRootPath(m_strImageRoot, m_strImageInfoFileName))
	{
		AfxMessageBox(_T("There is no image files. This program is going to be closed"));
		return FALSE;
	}

	return TRUE;
}

void CBBViewerApp::LoadImage()
{
	LPST_BMP_INFO  lpBmpInfo;
	int i;

	TCHAR *tzBmpInfoApp[MAX_BMPINFO] =
	{
		BMPINFO_APP_BACKGROUND,				//1. background
		BMPINFO_APP_FILEOPEN_N,
		BMPINFO_APP_FILEOPEN_F,
		BMPINFO_APP_FILEOPEN_S,
		BMPINFO_APP_FILEOPEN_D,
		BMPINFO_APP_DELETE_N,
		BMPINFO_APP_DELETE_F,
		BMPINFO_APP_DELETE_S,
		BMPINFO_APP_DELETE_D,
		BMPINFO_SYS_EXIT_N,
		BMPINFO_SYS_EXIT_F,
		BMPINFO_SYS_EXIT_S,
		BMPINFO_SYS_EXIT_D,
		BMPINFO_SYS_MAX_N,
		BMPINFO_SYS_MAX_F,
		BMPINFO_SYS_MAX_S,
		BMPINFO_SYS_MAX_D,
		BMPINFO_SYS_RESTORE_FROM_MAX_N,
		BMPINFO_SYS_RESTORE_FROM_MAX_F,
		BMPINFO_SYS_RESTORE_FROM_MAX_S,
		BMPINFO_SYS_RESTORE_FROM_MAX_D,
		BMPINFO_SYS_MIN_N,
		BMPINFO_SYS_MIN_F,
		BMPINFO_SYS_MIN_S,
		BMPINFO_SYS_MIN_D,
		BMPINFO_SYS_FULL_N,
		BMPINFO_SYS_FULL_F,
		BMPINFO_SYS_FULL_S,
		BMPINFO_SYS_FULL_D,
		BMPINFO_SYS_RESTORE_FROM_FULL_N,
		BMPINFO_SYS_RESTORE_FROM_FULL_F,
		BMPINFO_SYS_RESTORE_FROM_FULL_S,
		BMPINFO_SYS_RESTORE_FROM_FULL_D,
		BMPINFO_SYS_PANEL,
		BMPINFO_MENU_PRINT_N,
		BMPINFO_MENU_PRINT_F,
		BMPINFO_MENU_PRINT_S,
		BMPINFO_MENU_PRINT_D,
		BMPINFO_MENU_SETUP_N,
		BMPINFO_MENU_SETUP_F,
		BMPINFO_MENU_SETUP_S,
		BMPINFO_MENU_SETUP_D,
		BMPINFO_MENU_BACKUP_N,
		BMPINFO_MENU_BACKUP_F,
		BMPINFO_MENU_BACKUP_S,
		BMPINFO_MENU_BACKUP_D,
		BMPINFO_MENU_VIEWER_N,
		BMPINFO_MENU_VIEWER_F,
		BMPINFO_MENU_VIEWER_S,
		BMPINFO_MENU_VIEWER_D,
		BMPINFO_MENU_OPEN_N,
		BMPINFO_MENU_OPEN_F,
		BMPINFO_MENU_OPEN_S,
		BMPINFO_MENU_OPEN_D,
		BMPINFO_MENU_DELETE_N,
		BMPINFO_MENU_DELETE_F,
		BMPINFO_MENU_DELETE_S,
		BMPINFO_MENU_DELETE_D,

		BMPINFO_PLAY_FORWORD_N,
		BMPINFO_PLAY_FORWORD_F,
		BMPINFO_PLAY_FORWORD_S,
		BMPINFO_PLAY_FORWORD_D,
		BMPINFO_PAUSE_N,
		BMPINFO_PAUSE_F,
		BMPINFO_PAUSE_S,
		BMPINFO_PAUSE_D,
		BMPINFO_PLAY_BACKWORD_N,
		BMPINFO_PLAY_BACKWORD_F,
		BMPINFO_PLAY_BACKWORD_S,
		BMPINFO_PLAY_BACKWORD_D,
		BMPINFO_STOP_N,
		BMPINFO_STOP_F,
		BMPINFO_STOP_S,
		BMPINFO_STOP_D,
		BMPINFO_STEP_FORWORD_N,
		BMPINFO_STEP_FORWORD_F,
		BMPINFO_STEP_FORWORD_S,
		BMPINFO_STEP_FORWORD_D,
		BMPINFO_STEP_BACKWORD_N,
		BMPINFO_STEP_BACKWORD_F,
		BMPINFO_STEP_BACKWORD_S,
		BMPINFO_STEP_BACKWORD_D,
		BMPINFO_STEP_FORWORD_K_N,
		BMPINFO_STEP_FORWORD_K_F,
		BMPINFO_STEP_FORWORD_K_S,
		BMPINFO_STEP_FORWORD_K_D,
		BMPINFO_STEP_BACKWORD_K_N,
		BMPINFO_STEP_BACKWORD_K_F,
		BMPINFO_STEP_BACKWORD_K_S,
		BMPINFO_STEP_BACKWORD_K_D,
		BMPINFO_NEXT_FILE_N,
		BMPINFO_NEXT_FILE_F,
		BMPINFO_NEXT_FILE_S,
		BMPINFO_NEXT_FILE_D,
		BMPINFO_PREV_FILE_N,
		BMPINFO_PREV_FILE_F,
		BMPINFO_PREV_FILE_S,
		BMPINFO_PREV_FILE_D,

		BMPINFO_PB_SPEED_BK,
		BMPINFO_PB_SPEED_X1_4,
		BMPINFO_PB_SPEED_X1_2,
		BMPINFO_PB_SPEED_X1,
		BMPINFO_PB_SPEED_X2,
		BMPINFO_PB_SPEED_X4,
		BMPINFO_VOL_BK,
		BMPINFO_VOL_SLIDER,
		BMPINFO_VOL_THUMB,
		BMPINFO_SPEEDOMETER_BK,

		BMPINFO_BAR_L_DISABLED,
		BMPINFO_BAR_R_DISABLED,
		BMPINFO_BAR_M_DISABLED,
		BMPINFO_BAR_L_ENABLED,
		BMPINFO_BAR_R_ENABLED,
		BMPINFO_BAR_M_ENABLED,
		BMPINFO_BAR_THUMB,

		BMPINFO_TAB_TIME_U,
		BMPINFO_TAB_TIME_C,
		BMPINFO_TAB_TIME_D,
		BMPINFO_TAB_EVENT_U,
		BMPINFO_TAB_EVENT_C,
		BMPINFO_TAB_EVENT_D,

		BMPINFO_OPT_NORMAL_U,
		BMPINFO_OPT_NORMAL_C,
		BMPINFO_OPT_NORMAL_D,
		BMPINFO_OPT_EVENT_U,
		BMPINFO_OPT_EVENT_C,
		BMPINFO_OPT_EVENT_D,
		BMPINFO_OPT_PARKING_U,
		BMPINFO_OPT_PARKING_C,
		BMPINFO_OPT_PARKING_D,
		BMPINFO_OPT_MANUAL_U,
		BMPINFO_OPT_MANUAL_C,
		BMPINFO_OPT_MANUAL_D,

		BMPINFO_GSEN_GRAPH,
		BMPINFO_GSEN_INDI,
		BMPINFO_GSEN_COORDI,

		BMPINFO_COMMON_RADIO_U,
		BMPINFO_COMMON_RADIO_C,
		BMPINFO_COMMON_RADIO_D,

		BMPINFO_GPS_NORMAL_N,
		BMPINFO_GPS_NORMAL_F,
		BMPINFO_GPS_NORMAL_S,
		BMPINFO_GPS_NORMAL_D,
		BMPINFO_GPS_HIDE_N,
		BMPINFO_GPS_HIDE_F,
		BMPINFO_GPS_HIDE_S,
		BMPINFO_GPS_HIDE_D,
		BMPINFO_GPS_LARGE_N,
		BMPINFO_GPS_LARGE_F,
		BMPINFO_GPS_LARGE_S,
		BMPINFO_GPS_LARGE_D,

		BMPINFO_SCRL_VERT_TOP,
		BMPINFO_SCRL_VERT_BOTTOM,
		BMPINFO_SCRL_VERT_UPARROW,
		BMPINFO_SCRL_VERT_DOWNARROW,
		BMPINFO_SCRL_VERT_SPAN,
		BMPINFO_SCRL_VERT_THUMB,

		BMPINFO_SCRL_HORZ_LEFTARROW,
		BMPINFO_SCRL_HORZ_RIGHTARROW,
		BMPINFO_SCRL_HORZ_SPAN,
		BMPINFO_SCRL_HORZ_THUMB,

		BMPINFO_LIST_V_BORDER,
		BMPINFO_LIST_H_BORDER,
		BMPINFO_LIST_HEADER_START,
		BMPINFO_LIST_HEADER_END,
		BMPINFO_LIST_HEADER_SPAN,
		BMPINFO_LIST_CHECKBOX,
		BMPINFO_LIST_CHECKBOX_S,

		BMPINFO_PB_SPEED_SLOWER_N,
		BMPINFO_PB_SPEED_SLOWER_F,
		BMPINFO_PB_SPEED_SLOWER_S,
		BMPINFO_PB_SPEED_SLOWER_D,
		BMPINFO_PB_SPEED_FASTER_N,
		BMPINFO_PB_SPEED_FASTER_F,
		BMPINFO_PB_SPEED_FASTER_S,
		BMPINFO_PB_SPEED_FASTER_D,

		BMPINFO_OPT_BACKGROUND,
		BMPINFO_LIST_BACKGROUND,
		BMPINFO_MAP_BACKGROUND,
		BMPINFO_GSEN_GRAPH_BACKGROUND,
		BMPINFO_GSEN_BACKGROUND,

		BMPINFO_LOGO,
		BMPINFO_LOGO_REAR,

		BMPINFO_SETUP_MAIN,
		BMPINFO_APP_BACKGROUND_FULL,
		BMPINFO_TITLEBAR_LOGO,
	};

	for (i=0;i<MAX_BMPINFO;i++)
	{
		lpBmpInfo = new ST_BMP_INFO;
		ZeroMemory(lpBmpInfo, sizeof(ST_BMP_INFO));
		m_SupportImage.CreateBmpInfo(tzBmpInfoApp[i], lpBmpInfo);
		BmpInfo.Add(lpBmpInfo);
	}

}

void CBBViewerApp::UnloadImage()
{
	LPST_BMP_INFO lpBmpInfo;
	int i;
	for (i=0;i<BmpInfo.GetSize();i++)
	{
		lpBmpInfo = BmpInfo.GetAt(i);
		m_SupportImage.ReleaseBmpInfo(lpBmpInfo);
		delete lpBmpInfo;
	}
	BmpInfo.RemoveAll();
}

void CBBViewerApp::LoadWinInfo()
{
	LPST_WND_POS lpWndPos;

	TCHAR *tzWndInfoApp[MAX_WNDINFO] =
	{
		WININFO_APP_BACKGROUND,
		WININFO_APP_ROUNDRGN,
		WININFO_APP_SYSTEMMENU,
		WININFO_BTN_FILEOPEN,
		WININFO_BTN_DELETE,
		WININFO_TAB,
		WININFO_TAB_TIME,
		WININFO_TAB_EVENT,
		WININFO_OPT,
		WININFO_OPT_BG,
		WININFO_LIST_NORMAL,
		WININFO_LIST_LARGE,
		WININFO_LIST_HIDE,
		WININFO_MAP_NORMAL,
		WININFO_MAP_LARGE,
		WININFO_MAP_HIDE,
		WININFO_MAP_VIEW,

		WININFO_GPS_NORMAL,
		WININFO_GPS_LARGE,
		WININFO_GPS_VIEW,
		WININFO_GPS_TEXTBOX,
		WININFO_GPS_BTN_LARGE,
		WININFO_GPS_BTN_NORMAL,
		WININFO_GPS_BTN_HIDE,

		WININFO_PLAYBACK_CTRL,
		WININFO_PB_PLAY_FWD,
		WININFO_PB_PLAY_BWD,
		WININFO_PB_STEP_FWD,
		WININFO_PB_STEP_BWD,
		WININFO_PB_STEP_FWD_K,
		WININFO_PB_STEP_BWD_K,
		WININFO_PB_PAUSE,
		WININFO_PB_STOP,
		WININFO_PB_NEXT_FILE,
		WININFO_PB_PREV_FILE,

		WININFO_MENU_BUTTON,
		WININFO_MENU_PRINT,
		WININFO_MENU_BACKUP,
		WININFO_MENU_SETUP,
		WININFO_MENU_INFO,
		WININFO_MENU_OPEN,
		WININFO_MENU_DELETE,

		WININFO_PBSPEED,
		WININFO_PBSPEED_BK,
		WININFO_PBSPEED_STAT,
		WININFO_PBSPEED_SLOWER,
		WININFO_PBSPEED_FASTER,

		WININFO_VOLUME,
		WININFO_VOLUME_SLIDER,
		WININFO_SPEEDOMETER,

		WININFO_LIST_TIME,
		WININFO_LIST_TIME_DATE,
		WININFO_LIST_TIME_HOUR,
		WININFO_LIST_TIME_FILE,
		WININFO_LIST_EVENT,
		WININFO_LIST_EVENT_FILE,

		WININFO_GSENSOR_GRAPH,
		WININFO_GSENSOR_GRAPH_VIEW,
		WININFO_GSENSOR,
		WININFO_GSENSOR_VIEW,
		WININFO_GSENSOR_COORDI,
		WININFO_TIME_BAR,
		WININFO_TITLE_BAR,

		WININFO_MAIN_DISPLAY,
		WININFO_FULL_DISPLAY,

		WININFO_LIST_HEADER,

		WININFO_SETUP_MAIN,
		WININFO_SETUP_EXIT,
		WININFO_SETUP_PANEL,
		WININFO_TITLEBAR_LOGO,
	};

	int i;
	for (i=0;i<MAX_WNDINFO;i++)
	{
		lpWndPos = new ST_WND_POS;
		ZeroMemory(lpWndPos, sizeof(ST_WND_POS));
		m_SupportImage.GetWndInfo(tzWndInfoApp[i], lpWndPos);
		WndPos.Add(lpWndPos);
	}

}

void CBBViewerApp::UnloadWinInfo()
{
	LPST_WND_POS lpWndPos;
	int i;
	for (i=0;i<WndPos.GetSize();i++)
	{
		lpWndPos = WndPos.GetAt(i);
		delete lpWndPos;
	}
	WndPos.RemoveAll();
}

void CBBViewerApp::SetWindowPosition(CWnd *pWnd, int cx, int cy, CRect rtWnd, CRect rtStickTo, BOOL bShow, BOOL bVCenter, BOOL bHCenter)
{
	CRect rtPos;
	if (bHCenter)
	{
		rtPos.left = (cx-rtWnd.Width())/2;
		if (rtStickTo.left>0)
			rtPos.left += rtStickTo.left;
		else if (rtStickTo.right>0)
			rtPos.left -= rtStickTo.right;
		rtPos.right = rtPos.left + rtWnd.Width();
	}
	else if ((rtStickTo.left<0)&&(rtStickTo.right<0))
	{
		rtPos.left = rtWnd.left;
		rtPos.right = rtWnd.right;
	}
	else if ((rtStickTo.left>=0)&&(rtStickTo.right<0))
	{
		rtPos.left = rtStickTo.left;
		rtPos.right = rtStickTo.left+rtWnd.Width();
	}
	else if ((rtStickTo.left<0)&&(rtStickTo.right>=0))
	{
		rtPos.right = cx-rtStickTo.right;
		rtPos.left = rtPos.right - rtWnd.Width();
	}
	else
	{
		rtPos.left = rtStickTo.left;
		rtPos.right = cx-rtStickTo.right;
	}

	if (bVCenter)
	{
		rtPos.top = (cy - rtWnd.Height())/2;
		rtPos.bottom = rtPos.top + rtWnd.Height();
	}
	else if ((rtStickTo.top<0)&&(rtStickTo.bottom<0))
	{
		rtPos.top = rtWnd.top;
		rtPos.bottom = rtWnd.bottom;
	}
	else if ((rtStickTo.top>=0)&&(rtStickTo.bottom<0))
	{
		rtPos.top = rtStickTo.top;
		rtPos.bottom = rtStickTo.top+rtWnd.Height();
	}
	else if ((rtStickTo.top<0)&&(rtStickTo.bottom>=0))
	{
		rtPos.bottom = cy-rtStickTo.bottom;
		rtPos.top = rtPos.bottom - rtWnd.Height();
	}
	else
	{
		rtPos.top = rtStickTo.top;
		rtPos.bottom = cy-rtStickTo.bottom;
	}

	if (!bShow)
	{
		rtPos.bottom = rtPos.top;
	}
	pWnd->MoveWindow(rtPos);
}

CString CBBViewerApp::GetLogoPath()
{
	TCHAR tzPath[MAX_PATH];
	TCHAR tzValue[MAX_PATH];
	CString strImageRoot;
	CString strImageInfoPath;

	wsprintf(tzPath, _T("%s\\option"), m_strModulePath);
	CreateDirectory(tzPath, NULL);

	wsprintf(tzPath, _T("%s\\option\\ImagePath.ini"), m_strModulePath);

	int nSelect;
	CString strImagePath;
	nSelect = GetPrivateProfileInt(_T("Setting"), _T("Select"), 0, tzPath);

	strImagePath.Format(_T("Image Path%d"), nSelect);
	ZeroMemory(tzValue, sizeof(tzValue));
	GetPrivateProfileString(strImagePath, _T("Root Path"), NULL, tzValue, MAX_PATH, tzPath);
	strImageRoot.Format(_T("%s\\%s"), m_strModulePath, tzValue);
	ZeroMemory(tzValue, sizeof(tzValue));
	GetPrivateProfileString(strImagePath, _T("Info File Name"), NULL, tzValue, MAX_PATH, tzPath);
	strImageInfoPath.Format(_T("%s\\%s"), strImageRoot, tzValue);

	ZeroMemory(tzValue, sizeof(tzValue));

	CString strPath;
	if (GetPrivateProfileString(_T("Logo"), _T("Path"), NULL, tzValue, MAX_PATH, strImageInfoPath))
	{
		strPath.Format(_T("%s\\%s"), strImageRoot, tzValue);
	}
	else
	{
		strPath = _T("");
	}
	return strPath;
}